<!DOCTYPE html>
<!-- saved from url=(0229)file:///D:/%E5%A4%A7%E5%A4%A7%E5%B0%8F%E5%B0%8F%E7%9A%84%E6%88%98%E5%BD%B9/%E7%99%BE%E5%BA%A6%E5%89%8D%E7%AB%AF%E5%AD%A6%E9%99%A2/IFE-20-%2D21/%E4%BA%8B%E4%BB%B6dome1%E8%BF%94%E5%9B%9Ename%E4%B8%AD%E7%9A%84%E5%86%85%E5%AE%B9.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <title>事件</title>
</head>

<body>
    <input id="name" type="text">
    <button id="submit-btn">Submit</button>
<!--     <script>
    var btn = document.getElementById("submit-btn");
    btn.onclick = function() {
    var inputText = document.getElementById("name").value;
        console.log(inputText);
    }
    document.onkeydown = function getKey() {
        if (event.keyCode == 13) {
            var inputText = document.getElementById("name").value;
            console.log(inputText);
        }
        if (event.keyCode == 27) {
            var vacant = document.getElementById('name');
            vacant.value = "";
            vacant.focus();
        }
    }
    </script> -->
    <script>
        var btn = document.getElementById('submit-btn');
        btn.onclick = function () {
         inputText = document.getElementById('name').value;
            console.log(inputText);
        }
        document.onkeydown = function getKey() {
            if (event.keyCode == 13) {
                // var inputText = document.getElementById('name').value;
                console.log(inputText);
            }
            if (event.keyCode == 27) {
                var vacant =  document.getElementById('name');
                vacant.value = '';
                vacant.focus();
            }

        }
    </script>


</body></html>